package com.xiaoyi.intentsdklibrary.SDK.FloatView;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.v4.internal.view.SupportMenu;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.lkx.liandianqinew.R;
import com.xiaoyi.intentsdklibrary.Bean.AsToastBean;
import com.xiaoyi.intentsdklibrary.Bean.ViewBean;
import com.xiaoyi.intentsdklibrary.CheckUtil;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionAsSDK;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.Utils.ClickSDK;
import java.util.ArrayList;
import java.util.List;
import org.greenrobot.eventbus.EventBus;

public class NoteInfoViewSDK {
    public static OnChoseViewListener mOnChoseViewListener;
    private static final NoteInfoViewSDK ourInstance = new NoteInfoViewSDK();
    private List<ViewBean> mAllBeanList;
    private boolean mCanuUserLocationLimit;
    private Dialog mDialog;
    private FindViewType mFindViewType;
    private Handler mHandler;
    private NoteInfoView mNoteInfoView;
    private WindowManager.LayoutParams mParams;
    private Runnable mR;
    private WindowManager mWindowManager;

    public enum FindViewType {
        ALL,
        CLICK,
        LONGCLICK,
        INPUT,
        CHECKED,
        HAS_ID,
        HAS_ID_WAIT,
        HAS_TEXT,
        HAS_TEXT_WAIT,
        HAS_DES,
        HAS_CHECK,
        LISTVIEW
    }

    public enum NowActioType {
        CLICK,
        LONG_CLICK,
        INPUT,
        CHECK,
        UNCHECK,
        FIND_ID,
        FIND_ID_WAIT,
        FIND_TEXT,
        FIND_TEXT_WAIT,
        FIND_DES,
        FIND_CHECKED,
        LISTVIEW
    }

    public interface OnChoseViewListener {
        void result(ViewBean viewBean, String str);
    }

    public enum ViewLimitType {
        ID,
        TEXT,
        DES,
        LOCATION
    }

    public static NoteInfoViewSDK getInstance() {
        return ourInstance;
    }

    private NoteInfoViewSDK() {
    }

    public void chose(Context context, FindViewType findViewType, OnChoseViewListener onChoseViewListener) {
        ClickSDK.onlyVibrate(context);
        this.mFindViewType = findViewType;
        if (!ActionAsSDK.getInstance().checkAs(context)) {
            if (onChoseViewListener != null) {
                try {
                    onChoseViewListener.result(null, "请先打开无障碍权限！");
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
            }
            Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        } else if (CheckUtil.checkOp(context)) {
            ActionAsSDK.getInstance().init(context);
            List<ViewBean> allNode = ActionAsSDK.getInstance().getAllNode(findViewType);
            this.mAllBeanList = allNode;
            if (allNode == null) {
                this.mAllBeanList = new ArrayList();
            }
            if (this.mAllBeanList.size() > 0) {
                init(context);
                if (findViewType == FindViewType.LISTVIEW) {
                    show(true, findListBean(), onChoseViewListener);
                } else {
                    show(true, this.mAllBeanList, onChoseViewListener);
                }
            } else if (onChoseViewListener != null) {
                onChoseViewListener.result(null, "目标对象为0,请稍后再试！");
            }
        } else {
            ActionNormalSDK.getInstance().gotoFloatPermissionSetting(context);
        }
    }

    public void showFirstChild(OnChoseViewListener onChoseViewListener) {
        List<ViewBean> findChildeBean = findChildeBean();
        mOnChoseViewListener = onChoseViewListener;
        show(false, findChildeBean, onChoseViewListener);
    }

    public void choseListViewAction(NowActioType nowActioType, OnChoseViewListener onChoseViewListener) {
        List<ViewBean> findViewNum = findViewNum(nowActioType);
        if (findViewNum.size() == 0) {
            onChoseViewListener.result(null, "目标控件为0！");
            return;
        }
        mOnChoseViewListener = onChoseViewListener;
        show(false, findViewNum, onChoseViewListener);
    }

    private List<ViewBean> findListBean() {
        ArrayList arrayList = new ArrayList();
        for (ViewBean viewBean : this.mAllBeanList) {
            if (!viewBean.isListVieChild()) {
                arrayList.add(viewBean);
            }
        }
        return arrayList;
    }

    private List<ViewBean> findChildeBean() {
        ArrayList arrayList = new ArrayList();
        for (ViewBean viewBean : this.mAllBeanList) {
            if (viewBean.isListVieChild() && !TextUtils.isEmpty(viewBean.getTextValue())) {
                arrayList.add(viewBean);
            }
        }
        return arrayList;
    }

    private List<ViewBean> findViewNum(NowActioType nowActioType) {
        ArrayList arrayList = new ArrayList();
        for (ViewBean viewBean : this.mAllBeanList) {
            if (viewBean.isListVieChild()) {
                int i = nowActioType.ordinal();
                if (i != 1) {
                    if (i != 2) {
                        if (i != 3) {
                            if ((i == 4 || i == 5) && viewBean.isCanCheck()) {
                                arrayList.add(viewBean);
                            }
                        } else if (viewBean.isCanInput()) {
                            arrayList.add(viewBean);
                        }
                    } else if (viewBean.isCanLongClick()) {
                        arrayList.add(viewBean);
                    }
                } else if (viewBean.isCanClick()) {
                    arrayList.add(viewBean);
                }
            }
        }
        return arrayList;
    }

    private void init(Context context) {
        try {
            if (this.mWindowManager == null) {
                this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                this.mNoteInfoView = new NoteInfoView(context);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                this.mParams = layoutParams;
                layoutParams.flags = 128;
                this.mParams.format = -3;
                if (Build.VERSION.SDK_INT >= 26) {
                    this.mParams.type = 2038;
                } else {
                    this.mParams.type = 2003;
                }
                this.mParams.gravity = 8388659;
                this.mWindowManager.addView(this.mNoteInfoView, this.mParams);
                NoteInfoView noteInfoView = this.mNoteInfoView;
                if (noteInfoView != null) {
                    noteInfoView.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void show(boolean z, List<ViewBean> list, OnChoseViewListener onChoseViewListener) {
        hide();
        try {
            this.mCanuUserLocationLimit = z;
            mOnChoseViewListener = onChoseViewListener;
            this.mNoteInfoView.setPath(list);
            this.mWindowManager.updateViewLayout(this.mNoteInfoView, this.mParams);
            this.mNoteInfoView.setVisibility(View.VISIBLE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void hide() {
        try {
            NoteInfoView noteInfoView = this.mNoteInfoView;
            if (noteInfoView != null) {
                noteInfoView.setVisibility(View.GONE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showChoseView(final Context context, final List<ViewBean> list, final ViewBean viewBean) {
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            if (dialog.isShowing()) {
                this.mDialog.dismiss();
            }
            this.mDialog = null;
        }
        Dialog createSysDailog = createSysDailog(context, R.layout.dialog_viewbean_layout);
        this.mDialog = createSysDailog;
        TextView textView = (TextView) createSysDailog.findViewById(R.id.tv_title);
        final TextView textView2 = (TextView) this.mDialog.findViewById(R.id.id_id);
        TextView textView3 = (TextView) this.mDialog.findViewById(R.id.id_rect);
        TextView textView4 = (TextView) this.mDialog.findViewById(R.id.id_text);
        TextView textView5 = (TextView) this.mDialog.findViewById(R.id.id_des);
        TextView textView6 = (TextView) this.mDialog.findViewById(R.id.id_center);
        TextView textView7 = (TextView) this.mDialog.findViewById(R.id.id_classname);
        TextView textView8 = (TextView) this.mDialog.findViewById(R.id.id_packname);
        TextView textView9 = (TextView) this.mDialog.findViewById(R.id.id_activity);
        TextView textView10 = (TextView) this.mDialog.findViewById(R.id.id_child);
        TextView textView11 = (TextView) this.mDialog.findViewById(R.id.id_check);
        LinearLayout linearLayout = (LinearLayout) this.mDialog.findViewById(R.id.id_can_layout);
        TextView textView12 = (TextView) this.mDialog.findViewById(R.id.id_can_click);
        TextView textView13 = (TextView) this.mDialog.findViewById(R.id.id_can_longclick);
        TextView textView14 = (TextView) this.mDialog.findViewById(R.id.id_can_check);
        TextView textView15 = (TextView) this.mDialog.findViewById(R.id.id_can_input);
        TextView textView16 = (TextView) this.mDialog.findViewById(R.id.id_can_swip);
        TextView textView17 = (TextView) this.mDialog.findViewById(R.id.id_id_copy);
        if (this.mFindViewType != FindViewType.ALL) {
            linearLayout.setVisibility(View.GONE);
            switch (this.mFindViewType.ordinal()) {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    textView.setText("您确定选择此控件吗？");
                    break;
                case 6:
                case 7:
                    textView.setText("您确定选择此控件的ID作为判断条件吗？");
                    break;
                case 8:
                case 9:
                    textView.setText("您确定选择此控件的内容作为判断条件吗？");
                    break;
                case 10:
                    textView.setText("您确定选择此控件的描述作为判断条件吗？");
                    break;
                case 11:
                    textView.setText("您确定选择此控件当前状态作为判断条件吗？");
                    break;
            }
        } else {
            textView.setText("当前控件属性");
            linearLayout.setVisibility(View.VISIBLE);
            textView12.setText(viewBean.isCanClick() ? "是" : "否");
            textView13.setText(viewBean.isCanLongClick() ? "是" : "否");
            textView14.setText(viewBean.isCanCheck() ? "是" : "否");
            textView15.setText(viewBean.isCanInput() ? "是" : "否");
            textView16.setText(viewBean.isCanSwipe() ? "是" : "否");
            int i = -7829368;
            textView12.setTextColor(viewBean.isCanClick() ? -65536 : -7829368);
            textView13.setTextColor(viewBean.isCanLongClick() ? -65536 : -7829368);
            textView14.setTextColor(viewBean.isCanCheck() ? -65536 : -7829368);
            textView15.setTextColor(viewBean.isCanInput() ? -65536 : -7829368);
            if (viewBean.isCanSwipe()) {
                i = -65536;
            }
            textView16.setTextColor(i);
        }
        textView2.setText(viewBean.getViewID() + "");
        textView4.setText(viewBean.getTextValue() + "");
        textView5.setText(viewBean.getDesValue() + "");
        textView11.setText(viewBean.isCheckState() ? "是" : "否");
        if (this.mFindViewType.equals(FindViewType.HAS_ID)) {
            textView2.setTextColor(-65536);
        } else if (this.mFindViewType.equals(FindViewType.HAS_ID_WAIT)) {
            textView2.setTextColor(-65536);
        } else if (this.mFindViewType.equals(FindViewType.HAS_TEXT)) {
            textView4.setTextColor(-65536);
        } else if (this.mFindViewType.equals(FindViewType.HAS_TEXT_WAIT)) {
            textView4.setTextColor(-65536);
        } else if (this.mFindViewType.equals(FindViewType.HAS_DES)) {
            textView5.setTextColor(-65536);
        } else if (this.mFindViewType.equals(FindViewType.HAS_CHECK)) {
            textView11.setTextColor(-65536);
        }
        textView3.setText("W:" + viewBean.getRect().width() + ",H:" + viewBean.getRect().height() + ",Level:" + viewBean.getDrawLevel());
        StringBuilder sb = new StringBuilder();
        sb.append(viewBean.getCenterX());
        sb.append(",");
        sb.append(viewBean.getCenterY());
        textView6.setText(sb.toString());
        textView7.setText(viewBean.getClassName() + "");
        textView8.setText(viewBean.getPackName() + "");
        textView9.setText(viewBean.getActivityName() + "");
        textView10.setText(viewBean.isFinalView() ? "否" : "是");
        ((TextView) this.mDialog.findViewById(R.id.tv_cancle)).setOnClickListener(new View.OnClickListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass1 */

            public void onClick(View view) {
                ClickSDK.onlyVibrate(context);
                NoteInfoViewSDK.this.mDialog.dismiss();
            }
        });
        ((TextView) this.mDialog.findViewById(R.id.tv_sure)).setOnClickListener(new View.OnClickListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass2 */

            public void onClick(View view) {
                ClickSDK.onlyVibrate(context);
                NoteInfoViewSDK.this.mDialog.dismiss();
                NoteInfoViewSDK.this.hide();
                if (NoteInfoViewSDK.this.mFindViewType == FindViewType.ALL) {
                    if (NoteInfoViewSDK.mOnChoseViewListener != null) {
                        NoteInfoViewSDK.mOnChoseViewListener.result(viewBean, "！");
                    }
                } else if (NoteInfoViewSDK.this.mCanuUserLocationLimit) {
                    NoteInfoViewSDK.this.checkLimit(context, list, viewBean);
                } else {
                    viewBean.setViewLimitType(ViewLimitType.ID);
                    viewBean.setLimitValue(viewBean.getViewID() + "");
                    if (NoteInfoViewSDK.mOnChoseViewListener != null) {
                        NoteInfoViewSDK.mOnChoseViewListener.result(viewBean, "选择成功！");
                    }
                }
            }
        });
        textView17.setOnClickListener(new View.OnClickListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass3 */

            public void onClick(View view) {
                String trim = textView2.getText().toString().trim();
                if (!TextUtils.isEmpty(trim)) {
                    ClickSDK.onlyVibrate(context);
                    NoteInfoViewSDK.this.mDialog.dismiss();
                    ActionNormalSDK.getInstance().setCopyText(context, trim);
                    EventBus.getDefault().post(new AsToastBean("ID复制成功！"));
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void checkLimit(Context context, List<ViewBean> list, ViewBean viewBean) {
        ArrayList arrayList = new ArrayList();
        if (!TextUtils.isEmpty(viewBean.getViewID())) {
            for (ViewBean viewBean2 : list) {
                if (!TextUtils.isEmpty(viewBean2.getViewID()) && viewBean2.getViewID().equals(viewBean.getViewID())) {
                    arrayList.add(viewBean2);
                }
            }
        }
        if (arrayList.size() == 0) {
            if (!TextUtils.isEmpty(viewBean.getTextValue()) || !TextUtils.isEmpty(viewBean.getDesValue())) {
                choseLimitDialog(context, viewBean);
                return;
            }
            viewBean.setViewLimitType(ViewLimitType.LOCATION);
            viewBean.setLimitValue(viewBean.getRect().toString());
            OnChoseViewListener onChoseViewListener = mOnChoseViewListener;
            if (onChoseViewListener != null) {
                onChoseViewListener.result(viewBean, "选择成功！");
            }
        } else if (arrayList.size() == 1) {
            viewBean.setViewLimitType(ViewLimitType.ID);
            viewBean.setLimitValue(viewBean.getViewID());
            OnChoseViewListener onChoseViewListener2 = mOnChoseViewListener;
            if (onChoseViewListener2 != null) {
                onChoseViewListener2.result(viewBean, "选择成功！");
            }
        } else if (!TextUtils.isEmpty(viewBean.getTextValue()) || !TextUtils.isEmpty(viewBean.getDesValue())) {
            choseLimitDialog(context, viewBean);
        } else {
            viewBean.setViewLimitType(ViewLimitType.LOCATION);
            viewBean.setLimitValue(viewBean.getRect().toString());
            OnChoseViewListener onChoseViewListener3 = mOnChoseViewListener;
            if (onChoseViewListener3 != null) {
                onChoseViewListener3.result(viewBean, "选择成功！");
            }
        }
    }

    public void choseLimitDialog(final Context context, final ViewBean viewBean) {
        Dialog dialog = this.mDialog;
        if (dialog != null) {
            if (dialog.isShowing()) {
                this.mDialog.dismiss();
            }
            this.mDialog = null;
        }
        Dialog createSysDailog = createSysDailog(context, R.layout.dialog_chose_limit);
        this.mDialog = createSysDailog;
        TextView textView = (TextView) createSysDailog.findViewById(R.id.tv_title);
        final RadioButton radioButton = (RadioButton) this.mDialog.findViewById(R.id.id_location);
        ((TextView) this.mDialog.findViewById(R.id.id_location_value)).setText(viewBean.getRect().toString());
        final RadioButton radioButton2 = (RadioButton) this.mDialog.findViewById(R.id.id_text);
        TextView textView2 = (TextView) this.mDialog.findViewById(R.id.id_text_value);
        LinearLayout linearLayout = (LinearLayout) this.mDialog.findViewById(R.id.id_text_layout);
        View findViewById = this.mDialog.findViewById(R.id.id_text_layout_line);
        final RadioButton radioButton3 = (RadioButton) this.mDialog.findViewById(R.id.id_des);
        TextView textView3 = (TextView) this.mDialog.findViewById(R.id.id_des_value);
        LinearLayout linearLayout2 = (LinearLayout) this.mDialog.findViewById(R.id.id_des_layout);
        View findViewById2 = this.mDialog.findViewById(R.id.id_des_layout_line);
        if (TextUtils.isEmpty(viewBean.getTextValue())) {
            linearLayout.setVisibility(View.GONE);
            findViewById.setVisibility(View.GONE);
        } else {
            linearLayout.setVisibility(View.VISIBLE);
            findViewById.setVisibility(View.VISIBLE);
            textView2.setText(viewBean.getTextValue());
        }
        if (TextUtils.isEmpty(viewBean.getDesValue())) {
            linearLayout2.setVisibility(View.GONE);
            findViewById2.setVisibility(View.GONE);
        } else {
            linearLayout2.setVisibility(View.VISIBLE);
            findViewById2.setVisibility(View.VISIBLE);
            textView3.setText(viewBean.getDesValue());
        }
        radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass4 */

            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                if (z) {
                    radioButton2.setChecked(false);
                    radioButton3.setChecked(false);
                }
            }
        });
        radioButton2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass5 */

            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                if (z) {
                    radioButton.setChecked(false);
                    radioButton3.setChecked(false);
                }
            }
        });
        radioButton3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass6 */

            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                if (z) {
                    radioButton.setChecked(false);
                    radioButton2.setChecked(false);
                }
            }
        });
        TextView textView4 = (TextView) this.mDialog.findViewById(R.id.tv_sure);
        ((TextView) this.mDialog.findViewById(R.id.tv_cancle)).setOnClickListener(new View.OnClickListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass7 */

            public void onClick(View view) {
                ClickSDK.onlyVibrate(context);
                NoteInfoViewSDK.this.mDialog.dismiss();
            }
        });
        textView4.setOnClickListener(new View.OnClickListener() {
            /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.AnonymousClass8 */

            public void onClick(View view) {
                ClickSDK.onlyVibrate(context);
                NoteInfoViewSDK.this.mDialog.dismiss();
                NoteInfoViewSDK.this.hide();
                if (radioButton.isChecked()) {
                    viewBean.setViewLimitType(ViewLimitType.LOCATION);
                    viewBean.setLimitValue(viewBean.getRect().toString());
                }
                if (radioButton2.isChecked()) {
                    viewBean.setViewLimitType(ViewLimitType.TEXT);
                    ViewBean viewBean2 = viewBean;
                    viewBean2.setLimitValue(viewBean2.getTextValue());
                }
                if (radioButton3.isChecked()) {
                    viewBean.setViewLimitType(ViewLimitType.DES);
                    ViewBean viewBean3 = viewBean;
                    viewBean3.setLimitValue(viewBean3.getDesValue());
                }
                if (NoteInfoViewSDK.mOnChoseViewListener != null) {
                    NoteInfoViewSDK.mOnChoseViewListener.result(viewBean, "选择成功！");
                }
            }
        });
    }

    private static Dialog createSysDailog(Context context, int i) {
        Dialog dialog = new Dialog(context);
        if (!CheckUtil.checkOp(context)) {
            ActionNormalSDK.getInstance().gotoFloatPermissionSetting(context);
        }
        try {
            dialog.requestWindowFeature(1);
            dialog.setContentView(i);
            Window window = dialog.getWindow();
            window.setBackgroundDrawableResource(R.drawable.dialog_ffbg);
            WindowManager.LayoutParams attributes = window.getAttributes();
            window.setGravity(17);
            if (Build.VERSION.SDK_INT >= 26) {
                window.setType(2038);
            } else {
                window.setType(2003);
            }
            attributes.width = -2;
            attributes.height = -2;
            window.setAttributes(attributes);
            dialog.show();
        } catch (Exception e) {
            e.printStackTrace();
            ActionNormalSDK.getInstance().gotoFloatPermissionSetting(context);
        }
        return dialog;
    }
}
